package com.zbkj.service.coupons.controller;

import com.zbkj.common.request.OrderPayRequest;
import com.zbkj.common.response.OrderPayResultResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.coupons.request.BalanceToCouponRequest;
import com.zbkj.service.coupons.service.CouponsPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("api/front/coupons")
@Api(tags = "消费券支付管理")
public class CouponsController {

    @Autowired
    CouponsPayService payService;

    @ApiOperation(value = "订单支付")
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    public CommonResult<OrderPayResultResponse> payment(@RequestBody @Validated OrderPayRequest orderPayRequest) {
        return CommonResult.success(payService.payment(orderPayRequest));
    }

    @ApiOperation(value = "储值余额兑换消费券")
    @RequestMapping(value = "/exchangeBalance", method = RequestMethod.POST)
    public CommonResult<String> balanceToCoupons(@RequestBody @Validated BalanceToCouponRequest request) {
        String result = payService.balanceToCoupons(request);
        return CommonResult.success(result);
    }
}
